//创建连接对象
if (window.XMLHttpRequest){
    var request = new XMLHttpRequest();//创建ajax链接对象
}
else if (window.ActiveXObject){
    var request = new ActiveXObject();
}

//连接获取到php传回的文本
function link(){
    if (request.readyState == 4 && request.status == 200) {
        document.getElementById("main").innerHTML = request.responseText;
    }
}

//显示个人信息
function showInformation(id) {
    if (request != null){
        request.onreadystatechange = link;
        request.open("GET","PersonalDo.php?id="+id+"&type=1",true)
        request.send();
    }

}

//修改个人信息
function  changeInformation(id){
    if (request != null){
        request.onreadystatechange = link;
        request.open("GET","PersonalDo.php?id="+id+"&type=7",true)
        request.send();
    }

}



//进入发布新闻的界面
function createNews(){
    window.location.href="newssubmit.php";
}

//通过两个不同的函数传入type不同值来进行分支判断 在PersonalDo.php中
function showNews(id ,page) {
    if (request != null){
        request.onreadystatechange = link;
        request.open("GET","PersonalDo.php?id="+id+"&type=2&page="+page,true)
        request.send();
    }
}

//展示所有新闻
function showAllnews(page){
    if (request != null){
        request.onreadystatechange = link;
        request.open("GET","PersonalDo.php?type=3&page="+page,true)
        request.send();
    }
}

//展示个人发布的评论
function showComment(id,page){
    if (request != null){
        request.onreadystatechange = link;
        request.open("GET","PersonalDo.php?id="+id+"&type=4&page="+page,true)
        request.send();
    }
}

//展示所有的评论
function showAllComment(page)
{
    if (request != null){
        request.onreadystatechange = link;
        request.open("GET","PersonalDo.php?type=5&page="+page,true)
        request.send();
    }
}

//展示所有的非管理员用户
function showUsers(page){
    if (request != null){
        request.onreadystatechange = link;
        request.open("GET","PersonalDo.php?type=6&page="+page,true)
        request.send();
    }
}

//返回首页的界面
function returnIndex(){
    window.location.href="index.php";
}

//打开时判断要打开的指定页面,直接条跳转
function checkType(type,id){
    if(type==1) {
        showInformation(id)
    }

    else if(type == 2){
        showNews(id,1)
    }
    else if(type == 3){
        showAllNews(1)
    }
    else if(type==4){
        showComment(id,1)
    }
    else if(type==5){
        showAllComment(1)
    }
    else if(type == 6){
        showUsers(1)
    }
    else if(type==7){
        changeInformation(id)
    }
}

function checkchange(formobj){
    var name=document.getElementById("name").value;
    var password=document.getElementById("password").value;
    var passwordconfirm=document.getElementById("password-confirm").value;
    var email=document.getElementById("email").value;
    var phone=document.getElementById("phone").value;
    var changeSubmit=document.getElementById("changeSubmit");
    if(name.length==0){
        alert("姓名不能为空");
        window.event.preventDefault();
    }
    else if(password != passwordconfirm){
        alert("密码不一致");
        window.event.preventDefault();
    }
    else if(email.length==0){
        alert("邮箱不能为空");
        window.event.preventDefault();
    }
    else if(phone.length==0){
        alert("手机号不能为空");
        window.event.preventDefault();
    }
}





